package com.perceptivesoftware.security;

import java.sql.Driver;
import org.springframework.jdbc.datasource.SimpleDriverDataSource;
import org.springframework.util.ClassUtils;
import com.perceptivesoftware.licensing.server.handler.PropertiesHandler;

/**
 * A simple database driver using properties from the properties file
 * 
 * Copyright 2012 Perceptive Software Confidential and Proprietary Perceptive Licensing
 * 
 * @author Sean Langford
 * 
 */
public class DbAuthenticationDataSource extends SimpleDriverDataSource {

	final PropertiesHandler propertiesHandler = new PropertiesHandler();

	@SuppressWarnings("unchecked")
	public DbAuthenticationDataSource() throws DbAuthenticationConnectionConfigurationException {
		try {
			setDriverClass((Class<? extends Driver>) ClassUtils.forName(propertiesHandler.getProperty("auth_database.driver"), null));
			setUrl(propertiesHandler.getProperty("auth_database.url"));
		}
		catch (final ClassNotFoundException e) {
			throw new DbAuthenticationConnectionConfigurationException("Driver Class Not Found", e);
		}
		catch (final LinkageError e) {
			throw new DbAuthenticationConnectionConfigurationException("Linkage Error", e);
		}

	}
}
